package bankcontrol.bankcontrol.mvc;
 
import java.security.Principal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import bankcontrol.bankcontrol.domain.Member;
import bankcontrol.bankcontrol.repo.MemberDao;
import bankcontrol.bankcontrol.valueObjects.Account;


 
@Controller
public class LoginController {
 
	@Autowired
    private MemberDao memberDao;
	private Logger log  = LoggerFactory.getLogger(LoginController.class);
	
	@RequestMapping(value="/welcome", method = RequestMethod.GET)
	public ModelAndView printWelcome(ModelMap model, Principal principal ) {
 
		String name = principal.getName();
		model.addAttribute("username", name);
		model.addAttribute("message", "Welcome Ubuntu Users");
		
		if ((!name.equals(null)) && (!name.equals(""))) {
		      System.out.println("findbugs......");
		}
		
		 /*model.addAttribute("newMember", new Member());
	     model.addAttribute("members", memberDao.findAllOrderedByName());*/
		log.info("Inside printWelcome........");
		
		return new ModelAndView("index", "SpringWeb", new Account());
		//return "hello";
 
	}
 
	@RequestMapping(value="/login", method = RequestMethod.GET)
	public String login(ModelMap model) {
 
		return "login";
 
	}
	
	@RequestMapping(value="/loginfailed", method = RequestMethod.GET)
	public String loginerror(ModelMap model) {
 
		model.addAttribute("error", "true");
		return "login";
 
	}
	
	@RequestMapping(value="/logout", method = RequestMethod.GET)
	public String logout(ModelMap model) {
 
		return "login";
 
	}
	
}